package com.example.designpattern.responsibility.validator;

import com.example.designpattern.responsibility.AbstractValidator;
import com.example.designpattern.responsibility.config.ValidatorEnum;
import com.example.model.GoodsDTO;
import org.springframework.stereotype.Service;

/**
 * 长度校验
 *
 * @author long
 * @date 2024/4/20 10:44
 */
//@Service
public class LengthValidator extends AbstractValidator {

    @Override
    protected void doValidate(GoodsDTO dto) {
        if(dto.getGoodsName().length() > 100){
            throw new RuntimeException("商品名称长度不能超过100");
        }
    }

    @Override
    protected void preValidate(GoodsDTO dto) {
        logger.info("----------长度校验开始----------");
    }

    @Override
    protected void postValidate(GoodsDTO dto) {
        logger.info("----------长度校验结束----------");
    }

    @Override
    public ValidatorEnum type() {
        return ValidatorEnum.LENGTH;
    }

}
